const { data } = require('./mock')
const bodyParser = require('body-parser')

module.exports = app => {
    app.use(bodyParser.json())

    app.post('/api/getList', (req, res) => {
        let { status } = req.body

        status = status * 1

        // 同过订单状态筛选  为0 就返回所有数据
        if (status) {
            res.send({
                code: 1,
                data: data.filter(item => item.status === status)
            })
        } else {
            res.send({
                code: 1,
                data
            })
        }

    })

    app.post('/api/getDetail', (req, res) => {
        const { id } = req.body

        res.send({
            code: 1,
            data: data.find(item => item.id === id)
        })
    })
}